﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Billing.DataObjects;
using System.Linq;
namespace Billing.Transactions
{
    public partial class OtherPaymentTransaction : Billing.Transactions.TransactionBase
    {
        public OtherPaymentTransaction()
        {
            InitializeComponent();
        }

        AccountsView Client = null;

        private void trvClient_ChooseBootonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            Billing.Win.AccountsSelectionForm frm = new Billing.Win.AccountsSelectionForm(false);
            frm.AllowSelect = true;

            if (frm.ShowDialog() == DialogResult.OK)
            {
                Client = (AccountsView)frm.SelectedObjects[0].CurrentObject;
                this.trvClient.BaseObject = Client;
            }
        }
        public override void OnDataLoad()
        {
            base.OnDataLoad();
            this.bsPaymentPoints.DataSource = from i in this.BillingDataContext.PaymentPoints
                                              where i.PaymentPointTypeID == 4
                                              select i;
            this.cmbPaymentPoint.Value = 9;
        }

        public override void OnSave()
        {
            try
            {
                decimal Amount;
                Amount = Convert.ToDecimal(this.txtSrcAmount.Value);
                if (Amount == 0)
                {
                    this.ShowWarning("ნულოვან თანხაზე გატარება დაუშვებელია!");
                    return;
                }
                this.CurrentHeader.HeaderTypeID = 7;
                this.CurrentHeader.Description = this.txtDescription.Text;
                this.CurrentHeader.PaymentPointID = (Int16)this.cmbPaymentPoint.Value;

                this.AddNewLine();
                this.CurrentLine.AccountID = Client.ID;
                this.CurrentLine.Amount = Amount;

                base.OnSave();
            }
            catch (Exception ex)
            {
                this.ShowError(ex);
            }
            this.Close();
        }
    }
}
